package com.wl.myclocksource.init;

import com.wl.myclocksource.lister.MyLister;
import com.wl.myclocksource.utils.SerialPortUtil;
import gnu.io.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.TooManyListenersException;


/**
 * @author liwangwang
 * @site Liwangwang321@163.com
 * @create 2020-11-10 15:23
 */
@Component
public class PortInit implements ApplicationRunner {

    public  static  SerialPort serialPort =null;

    @Value("${portname}")
    private String portname;


    @Override
    public void run(ApplicationArguments args) throws Exception {

        System.out.println("当前portname:"+portname);
        TestA();
        //查看所有串口
        SerialPortUtil serialPortUtil = SerialPortUtil.getSerialPortUtil();
        ArrayList<String> port = serialPortUtil.findPort();
        port.forEach(u-> System.out.println("发现："+u.toString()));

    }

    private void TestA(){
        try {
            String str = System.getProperty("sun.arch.data.model");
            System.out.println("This JVM is " + str + "-bit");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}
